import { listData } from "../api/part"
const part = {
    namespaced: true,
    state: {
        list: [],
        newList: [],
        total: 0,
        page: 0,
        pageSize: 20,
        lists: []
    },
    mutations: {
        SET_LIST(state, list) {
            state.list = []
            state.newList = []
            list.data.forEach(val => {
                if (state.newList.indexOf(val.id) == -1) {
                    state.newList.push(val.id)
                    state.list.push(val)
                }
            })
            state.lists = state.list
            state.total = state.list.length
        },
        SET_LISTS(state) {
            state.lists = [...state.list, ...state.list.slice(state.page, state.pageSize)]
        },
        SET_PAGE(state, page) {
            state.page += page
            state.pageSize += page
        }
    },
    actions: {
        async GET_LIST({ commit }) {
            let res = await listData()
            commit("SET_LIST", res.data)
        }
    }
}
export default part